﻿using MoetutuServer.Helper;
using MoetutuServer.PublishHelper;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MoetutuServer.WebSite.Konachan
{
    class ArticleHelper
    {
        /// <summary>
        /// 创建文章并且唤起发布
        /// </summary>
        /// <param name="ImgUrl">正文图片URL</param>
        /// <param name="PreViewUrl">预览图URL</param>
        /// <param name="TAG">TAG</param>
        /// <param name="Source">转载来源</param>
        public static bool CreateContent(string ImgUrl, string PreViewUrl, string TAG, String Source)
        {

            string Content = "";
            List<string> TagListTemp = GetTags(TAG);
            List<String> ImgList = UploadImg.GetPicBed(ImgUrl, "Konachan");
            if (ImgList.Count >= 2)//防止数据越界异常
                Content = PublishHelper.CreateContent.EstablishContentAndCopyright(TagListTemp, ImgList, Source);
            else
                return false;
            if (MoetutuServer.Helper.PublishHelper.TagHelper.ExistenceTag(TagListTemp, StaticValue.ExcludeRomeKey)) {
                
                return false;
            }
         
            string Title = CreateTitle.Title(TagListTemp);
            Content.Replace("konachan.com/post/show", "konachan.net/post/show");
            Console.WriteLine("K站信息就绪");

            return PostHelper.WordPressPostHelper.Publish(StaticValue.PostUser, Title, Content, TagListTemp, PreViewUrl,new List<int>() { 10606 ,1});

        }


        private static List<string> GetTags(string TAG)
        {
            List<string> TagList = TAG.Split(Convert.ToChar(" ")).ToList<string>();
            TagList = Helper.PublishHelper.TagHelper.TranslateTag(TagList);
            return TagList;
        }
    }
}
